
#include	"SysConfig.h"
#include	"Define.h"
#include	"Port.h"
#include	"Function.h"
#include	"Model_Option.h"

#ifdef  MODEL_ARA5040
#define	AUX_NONE	1
#define	AUX_IN		0
#else
#define	AUX_NONE	0
#define	AUX_IN		1
#endif

unsigned char ucAUX_PortLast;
unsigned char ucAUX_Detected;
unsigned char ucAUX_DetectCheckCnt;

extern UI_FUNCTION FUNC_GetPreviousFunction(void);
extern unsigned short usCPU_ADC_Aux;	
extern unsigned char FUNC_PowerStatus(void);

#if  0
void FUNC_AUX_CheckDetect(void)
{
	if  ((ucFUNC_AUX_Detect == 0) && (ucAUX_Detected == 1))	// Added
	{
		FUNC_FunctionChangeStart(FUNC_AUX, FUNC_CHANGE_SEQ);
		ucFUNC_AUX_Detect = 1;
	}
}
#endif

#define	AUX_AD_VAL(X)	(X * 1023) / 3.3	

void AUX_PreDetect(void)
{
}

void AUX_Main(void)
{
#ifdef  MODEL_AGC505X
	
	if	(OPT_GetOption(OPT_MASK_AVC))
	{
		ucAUX_Detected = 0;
	}
	else
	{
		ucAUX_Detected = 1;
	}
#else
	if (AUX_AD_VAL(3.1) < usCPU_ADC_Aux)
	{
		if  (ucAUX_Detected == 1)
		{
			if  (++ucAUX_DetectCheckCnt > 2)
			{
				ucAUX_Detected = 0;
				if  ((FUNC_GetCurrentFunction() == FUNC_AUX) && (FUNC_PowerStatus()== 1))
				{
					DISP_ClearTempDisplayMode();
					MENU_Clear();
					FUNC_FunctionChangeStart(FUNC_GetPreviousFunction(),FUNC_CHANGE_SEQ0);
				}
			}
		}
	}
	else
	{
		ucAUX_Detected = 1;
		ucAUX_DetectCheckCnt = 0;
	}
#endif
}

